<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <title>微信菜单管理</title>
    <link rel="stylesheet" href="__ADMIN_STATICS__/bootstrap/dist/css/bootstrap.css" type="text/css" />
    <link rel="stylesheet" href="__ADMIN_STATICS__/animate.css/animate.css" type="text/css" />
    <link rel="stylesheet" href="__ADMIN_STATICS__/font-awesome/css/font-awesome.min.css" type="text/css" />
    <link rel="stylesheet" href="__ADMIN_STATICS__/simple-line-icons/css/simple-line-icons.css" type="text/css" />
    <link rel="stylesheet" href="__ADMIN_STATICS__/bootstrap-editable/css/bootstrap-editable.min.css" type="text/css" />
    <link rel="stylesheet" href="__ADMIN_STATICS__/app/css/font.css" type="text/css" />
    <link rel="stylesheet" href="__ADMIN_STATICS__/app/css/app.css" type="text/css" />
</head>
<body>
<div class="wrapper-md">
    <div class="panel panel-default">
        <div class="panel-heading">
            <div class="row">
                <div class="col-sm-3">
                    <a href="{:U('Admin/Index/welcome')}"><i class="fa fa-home"></i>&nbsp;首页</a>&nbsp;&gt;&nbsp;&nbsp;微信菜单管理
                </div>
            </div>
        </div>
        <div class="table-responsive">
            <form action="" method="post">
            <table class="table table-bordered table-striped table-hover table-condensed b-t b-light">
                <thead>
                    <tr>
                        <th>菜单名称</th>
                        <th>类型</th>
                        <th>值</th>
                    </tr>
                </thead>
                <tbody id="tbody">
                    <volist name="p_lists" id="list">
                        <!--父级操作-->

                        <tr class="pmenu{$list.id} menu{$list.id}" >
                            <td>
                                <input type="text" name="menu[{$list.id}][name]" class="form-control topmenu" value="{$list.name}" style="width: 50%;display: inline;" placeholder="菜单名称">
                                <a onclick="addcmenu({$list.id});" class="btn btn-primary"><i class="fa fa-plus"></i></a>
                                <a onclick="delmenu({$list.id});" class="btn btn-danger"><i class="fa fa-trash-o"></i></a>
                            </td>
                            <td class="sorting_1">
                                <select name="menu[{$list.id}][type]" class="form-control">
                                    <option <if condition="$list['type'] eq 'view'">selected</if> value="view">链接</option>
                                    <option <if condition="$list['type'] eq 'click'">selected</if> value="click">触发关键字</option>
                                    <option <if condition="$list['type'] eq 'scancode_push'">selected</if> value="scancode_push">扫码</option>
                                    <option <if condition="$list['type'] eq 'scancode_waitmsg'">selected</if> value="scancode_waitmsg"> 扫码（等待信息）</option>
                                    <option <if condition="$list['type'] eq 'pic_sysphoto'">selected</if> value="pic_sysphoto">系统拍照发图</option>
                                    <option <if condition="$list['type'] eq 'pic_photo_or_album'">selected</if> value="pic_photo_or_album">拍照或者相册发图</option>
                                    <option <if condition="$list['type'] eq 'pic_weixin'">selected</if> value="pic_weixin">微信相册发图</option>
                                    <option <if condition="$list['type'] eq 'location_select'">selected</if> value="location_select">地理位置</option>
                                </select>
                            </td>
                            <td>
                                <input class="form-control" type="text" value="{$list.value}" name="menu[{$list.id}][value]" placeholder="菜单值">
                                <input name="menu[{$list.id}][pid]" type="hidden" value="0">
                            </td>
                        </tr>
                        <!--父级操作-->

                        <volist name="c_lists" id="clist">
                            <if condition="$clist['pid'] eq $list['id']">
                                <tr class="pmenu{$list.id} menu{$clist.id}" >
                                    <td <if condition="$clist['pid'] gt 0">style="padding-left: 5em"</if>>
                                    <input class="form-control" type="text" name="menu[{$clist.id}][name]" value="{$clist.name}" style="width: 50%;display: inline;" placeholder="菜单名称">
                                    <a onclick="delmenu({$clist.id});" class="btn btn-danger"><i class="fa fa-trash-o"></i></a></td>
                                    <td class="sorting_1">
                                        <select name="menu[{$clist.id}][type]" class="form-control">
                                            <option <if condition="$clist['type'] eq 'view'">selected</if> value="view">链接</option>
                                            <option <if condition="$clist['type'] eq 'click'">selected</if> value="click">触发关键字</option>
                                            <option <if condition="$clist['type'] eq 'scancode_push'">selected</if> value="scancode_push">扫码</option>
                                            <option <if condition="$clist['type'] eq 'scancode_waitmsg'">selected</if> value="scancode_waitmsg"> 扫码（等待信息）</option>
                                            <option <if condition="$clist['type'] eq 'pic_sysphoto'">selected</if> value="pic_sysphoto">系统拍照发图</option>
                                            <option <if condition="$clist['type'] eq 'pic_photo_or_album'">selected</if> value="pic_photo_or_album">拍照或者相册发图</option>
                                            <option <if condition="$clist['type'] eq 'pic_weixin'">selected</if> value="pic_weixin">微信相册发图</option>
                                            <option <if condition="$clist['type'] eq 'location_select'">selected</if> value="location_select">地理位置</option>
                                        </select>
                                    </td>
                                    <td>
                                        <input class="form-control" type="text" value="{$clist.value}" name="menu[{$clist.id}][value]" placeholder="菜单值">
                                        <input name="menu[{$clist.id}][pid]" type="hidden" value="{$clist.pid}">
                                    </td>
                                </tr>
                            </if>
                        </volist>

                    </volist>
                </tbody>
            </table>

            <div class="panel-body">
                <button class="btn btn-primary " type="button" onclick="addpmenu()">
                    添加一级菜单<i class="fa fa-plus"></i>
                </button>
                <button class="btn btn-info " type="submit">
                    保存
                </button>
                <button class="btn btn-warning" type="button" onclick="publishMenu()">同步菜单</button>
            </div>
            </form>
        </div>
    </div>
</div>
<script src="__ADMIN_STATICS__/jquery/jquery.min.js"></script>
<script src="__ADMIN_STATICS__/bootstrap/dist/js/bootstrap.js"></script>
<script>
    var i  = {$max_id};
    //添加菜单
    function addpmenu(){
        var pmenu = $('.topmenu');
        if(pmenu.length >= 3){
            alert('最多三个一级菜单');  //alert('最多三个一级菜单');
            return;
        }
        i++;
        var id = i;
        var tpl = '<tr  class="pmenu__id__ menu__id__"><td><input type="text" name="menu[__id__][name]" value="" class="form-control topmenu" style="width: 50%;display: inline;" placeholder="菜单名称"><a onclick="addcmenu(__id__);" class="btn btn-primary"><i class="fa fa-plus"></i></a><a onclick="delmenu(__id__);" class="btn btn-danger"><i class="fa fa-trash-o"></i></a></td><td class="sorting_1"><select class="form-control" name="menu[__id__][type]"><option value="view">链接</option><option value="click">触发关键字</option><option value="scancode_push">扫码</option><option value="scancode_waitmsg"> 扫码（等待信息）</option><option value="pic_sysphoto">系统拍照发图</option><option value="pic_photo_or_album">拍照或者相册发图</option><option value="pic_weixin">微信相册发图</option><option value="location_select">地理位置</option></select></td><td><input class="form-control" type="text" value="" name="menu[__id__][value]" placeholder="菜单值"><input class="form-control" name="menu[__id__][pid]" type="hidden" value="0"></td></tr>';
        tpl = tpl.replace(/__id__/g,id);
        $('#tbody').append(tpl);
    }

    function addcmenu(pid){
        var cmenu = $('.pmenu'+pid);
        if(cmenu.length >= 6){
            alert('一级菜单下最多5个二级菜单');  //alert('一级菜单下最多5个二级菜单');
            return;
        }
        i++;
        var id = i;
        var tpl = '<tr class="odd pmenu__pid__ menu__id__" ><td class="" style="padding-left: 5em"><input type="text" class="form-control" name="menu[__id__][name]" value="" style="width: 50%;display: inline;" placeholder="菜单名称"><a onclick="delmenu(__id__);" class="btn btn-danger"><i class="fa fa-trash-o"></i></a></td><td class="sorting_1"><select  class="form-control" name="menu[__id__][type]"><option value="view">链接</option><option value="click">触发关键字</option><option value="scancode_push">扫码</option><option value="scancode_waitmsg"> 扫码（等待信息）</option><option value="pic_sysphoto">系统拍照发图</option><option value="pic_photo_or_album">拍照或者相册发图</option><option value="pic_weixin">微信相册发图</option><option value="location_select">地理位置</option></select></td><td><input class="form-control" type="text" value="" name="menu[__id__][value]" placeholder="菜单值"><input class="form-control" name="menu[__id__][pid]" type="hidden" value="__pid__"></td></tr>';
        tpl = tpl.replace(/__id__/g,id);
        tpl = tpl.replace(/__pid__/g,pid);
        $(cmenu.last()).after(tpl);
    }
    function publishMenu(){
        if(!confirm("确定同步吗？")){
            return;
        }
        $.ajax({
            url:'/index.php?m=Admin&c=WeiXin&a=publishMenu',
            type:'get',
            success:function(data){
                if(data.status==1){
                    alert(data.info);
                }else{
                    alert(data.info);
                }
            }
        });
    }
    function delmenu(id){
        if(!confirm("确定删除吗？")){
            return;
        }
        $.ajax({
            url:'/index.php?m=Admin&c=WeiXin&a=delMenu&id='+id,
            type:'get',
            success:function(data){
                if(data.status==1){
                    //删除子分类
                    $('.pmenu'+id).remove();
                    $('.menu'+id).remove();
                }else{
                    alert(data.info);
                }
            }
        });
    }

</script>
</body>
</html>
